<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp"%>
<style>
</style>
<script type="text/javascript">
    var quartzScheduleJobDataGrid;
    $(function() {
        quartzScheduleJobDataGrid = $('#quartzScheduleJobDataGrid').datagrid({
            url : '${path}/quartzScheduleJob/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            columns : [ [
            	 {
                     width : '100',
                     title : '任务',
                     field : 'jobName'
                 }, {
                     width : '100',
                     title : '任务组',
                     field : 'jobGroup'
                 },
                 {
                     width : '100',
                     title : '任务执行bean',
                     field : 'className'
                 },
                 
                 {
                 width : '100',
                 title : '任务执行方法',
                 field : 'methodName'
             },{
                width : '100',
                title : '执行参数',
                field : 'params',
            },{
                width : '100',
                title : 'cron表达式',
                field : 'cron'
            },
                {
                width : '100',
                title : '执行时间',
                field : 'runDate'
            },
                {
                width : '100',
                title : '状态',
                field : 'status',
                formatter:function(value,row,index){
                	  switch (value) {
                      case 1:
                          return '执行中';
                      case 0:
                          return '关闭';
                      case 2:
                          return '暂停';
                 	}
                }
            },
            {
                width : '100',
                title : '描述',
                field : 'desc'
            },
                {
                width : '100',
                title : '触发器',
                field : 'triggerName',
                hidden:true
            },
                {
                width : '100',
                title : '触发器组',
                field : 'triggerGroup',
                hidden:true
            },
               
            ]],
            frozenColumns : [ [{
                field : 'action',
                title : '操作',
                width : 250,
                formatter : function(value, row, index) {
                    var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="quartzScheduleJob-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editQuartzScheduleJobFun(\'{0}\');" >编辑</a>', row.jobName);
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="quartzScheduleJob-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteQuartzScheduleJobFun(\'{0}\',\'{1}\');" >删除</a>', row.jobName,row.jobGroup);
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="quartzScheduleJob-easyui-linkbutton-pause" data-options="plain:true,iconCls:\'fi-clock icon-green\'" onclick="pauseQuartzScheduleJobFun(\'{0}\',\'{1}\',\'{2}\');" >暂停</a>', row.jobName,row.jobGroup,row.status);
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.quartzScheduleJob-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.quartzScheduleJob-easyui-linkbutton-del').linkbutton({text:'删除'});
                $('.quartzScheduleJob-easyui-linkbutton-pause').linkbutton({text:'暂停/恢复'});
/*                 $('.quartzScheduleJob-easyui-linkbutton-view').linkbutton({text:'查看'}); */
            },
            toolbar : '#quartzScheduleJobToolbar'
        });
    });

    function addQuartzScheduleJobFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 500,
            height : '80%',
            href : '${path}/quartzScheduleJob/addPage',
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = quartzScheduleJobDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#quartzScheduleJobAddForm');
                    f.submit();
                }
            } ]
        });
    }

    function editQuartzScheduleJobFun(id) {
        if (id == undefined) {
            var rows = quartzScheduleJobDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            quartzScheduleJobDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 500,
            height : '80%',
            href : '${path}/quartzScheduleJob/editPage/' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = quartzScheduleJobDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#quartzScheduleJobEditForm');
                    f.submit();
                }
            } ]
        });
    }

    function deleteQuartzScheduleJobFun(jobName,jobGroup) {
        if (jobName == undefined) {//点击右键菜单才会触发这个
            var rows = quartzScheduleJobDataGrid.datagrid('getSelections');
            jobName = rows[0].jobName;
            jobGroup=rows[0].jobGroup
        } else {//点击操作里面的删除图标会触发这个
            quartzScheduleJobDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除吗？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path}/quartzScheduleJob/delete', {
                	"jobName":jobName,
                	"jobGroup":jobGroup
                }
                , function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        quartzScheduleJobDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
   
    function pauseQuartzScheduleJobFun(jobName,jobGroup,status){
    	var url="";
    	if(status==1){
    		//暂停
    		url=basePath+"/quartzScheduleJob/pauseJob";
    	}
    	if(status==2){
    		//恢復
    		url=basePath+"/quartzScheduleJob/resumeJob";
    	}
    	$.post(url,{
    		"jobName":jobName,
        	"jobGroup":jobGroup
        }
        , function(result) {
            if (result.success) {
                parent.$.messager.alert('提示', result.msg, 'info');
                quartzScheduleJobDataGrid.datagrid('reload');
            }
            progressClose();
        }, 'JSON');
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:true">
		<table id="quartzScheduleJobDataGrid"
			data-options="fit:true,border:false"></table>
	</div>
</div>
<div id="quartzScheduleJobToolbar" style="display: none;">
	<a onclick="addQuartzScheduleJobFun();" href="javascript:void(0);"
		class="easyui-linkbutton"
		data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
</div>
